package zkk.com.mengqu.fragment;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import zkk.com.mengqu.R;
import zkk.com.mengqu.adapter.KitchenShareAdapter;
import zkk.com.mengqu.view.refresh.LoadMoreListView;

/**
 * 厨房共享页面
 */
public class KitchenShareFragment extends Fragment{
    private  View view;
    private KitchenShareAdapter kitchenShareAdapter;
    private Context context;

    private LoadMoreListView listView;
    private SwipeRefreshLayout sf_lv_news_item_swipe_refresh;//下拉刷新
    private boolean isLoad = false;
    private boolean hasMore = true;
    private  String lastTime;//最后一个的时间

//    Observer<GameInfoBean> observer=new Observer<GameInfoBean>() {
//        @Override
//        public void onCompleted() {
//
//        }
//
//        @Override
//        public void onError(Throwable e) {
//        }
//
//        @Override
//        public void onNext(GameInfoBean result) {
//
//        }
//    };

    public static KitchenShareFragment newInstance(){
        KitchenShareFragment kitchenShareFragment = new KitchenShareFragment();
        return kitchenShareFragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.fragment_circle_friend,container,false);
        context = getActivity();
        initView();
        return view;
    }

    //声明
    private  void  initView(){
        listView=(LoadMoreListView) view.findViewById(R.id.lv_gameinfo);
        kitchenShareAdapter =new KitchenShareAdapter(context);
        listView.setAdapter(kitchenShareAdapter);

        sf_lv_news_item_swipe_refresh=(SwipeRefreshLayout)view.findViewById(R.id.sf_gameinfo_swipe_refresh);
        sf_lv_news_item_swipe_refresh.setColorSchemeColors(Color.GREEN, Color.RED, Color.YELLOW);
        sf_lv_news_item_swipe_refresh.setEnabled(true);

        listView.setOnLastItemVisibleListener(new LoadMoreListView.OnLastItemVisibleListener() {
            @Override
            public void onLastItemVisible() {

                if (isLoad || !hasMore) {
                    listView.setFooter(LoadMoreListView.Mode.NOMORE);
                    return;
                }
                isLoad = true;
                listView.setFooter(LoadMoreListView.Mode.LOAD);
            }
        });

    }

    //底部加载
//    private void getAppIndexMore(String dataType,String pageNo3){
//        isLoad =false;
//        //http://www.moeju.cn/api//gamenews?lastTime=0&dk=5ed40069e20354be&ak=~68EECA63-0FB4-1EB8-628D-CDCF663CEB41&v=2.1.0&os=a&channel=Xiaomi
//        APIManager.getwwwInstance().getgamenews(dataType,"5ed40069e20354be","~68EECA63-0FB4-1EB8-628D-CDCF663CEB41","2.1.0")
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(observer2);
//    }
}
